package com.zyh.tenant.controller;

import com.zyh.common.annotation.Log;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.common.core.page.TableDataInfo;
import com.zyh.common.enums.BusinessType;
import com.zyh.common.utils.poi.ExcelUtil;
import com.zyh.tenant.domain.TenantInfo;
import com.zyh.tenant.service.ITenantInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租客信息Controller
 * 
 * @author zyh
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/tenant/tenant")
public class TenantInfoController extends BaseController
{
    @Autowired
    private ITenantInfoService tenantInfoService;

    /**
     * 查询租客信息列表
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:list')")
    @GetMapping("/list")
    public TableDataInfo list(TenantInfo tenantInfo)
    {
        startPage();
        List<TenantInfo> list = tenantInfoService.selectTenantInfoList(tenantInfo);
        return getDataTable(list);
    }

    /**
     * 导出租客信息列表
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:export')")
    @Log(title = "租客信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantInfo tenantInfo)
    {
        List<TenantInfo> list = tenantInfoService.selectTenantInfoList(tenantInfo);
        ExcelUtil<TenantInfo> util = new ExcelUtil<TenantInfo>(TenantInfo.class);
        util.exportExcel(response, list, "租客信息数据");
    }

    /**
     * 获取租客信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tenantInfoService.selectTenantInfoById(id));
    }

    /**
     * 新增租客信息
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:add')")
    @Log(title = "租客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TenantInfo tenantInfo)
    {
        return toAjax(tenantInfoService.insertTenantInfo(tenantInfo));
    }

    /**
     * 修改租客信息
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:edit')")
    @Log(title = "租客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TenantInfo tenantInfo)
    {
        return toAjax(tenantInfoService.updateTenantInfo(tenantInfo));
    }

    /**
     * 删除租客信息
     */
    @PreAuthorize("@ss.hasPermi('tenant:tenant:remove')")
    @Log(title = "租客信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tenantInfoService.deleteTenantInfoByIds(ids));
    }
}
